Ext.define('AM.controller.Layout', {
	extend : 'Ext.app.Controller',

	stores : [ 'NavItems' ],

	models : [ 'NavItem' ],

	views : [ 
	          'layout.Nav', 
	          'test.List' , 
	          'user.List' ,
	          'ctulog.List',
	          'hightchart.Chart'
	          ],

	refs : [ {
		ref : 'nav',
		selector : 'layoutnav'
	}, {
		ref : 'viewer',
		selector : 'viewer'
	}, {
		ref : 'navData',
		selector : 'layoutnav dataview'
	}],

	requires : [ 'AM.store.NavItems' ],
	init : function() {
		this.control({
			'layoutnav dataview' : {
				itemclick : this.loadView
			}
		});
	},

	onLaunch : function() {
		var dataview = this.getNavData(), store = this.getNavItemsStore();

		dataview.bindStore(store);
		// dataview.getSelectionModel().select(store.getAt(0));
	},
	loadView : function( me, record, item, index, e, eOpts) {
		var viewer = this.getViewer();
		var tab = null;
		var xtype = record.get('xtype');
		tab = viewer.queryById(xtype);
		if (Ext.isEmpty(tab)) {
			tab = Ext.widget(xtype);
			tab.closable = true;
			tab.id = xtype;
			viewer.add(tab);
		}
		viewer.setActiveTab(tab);
	}
});